<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生信息</title>
    <!--<link rel="stylesheet" href="/css/layui.css">-->
</head>
<body>
<form class="layui-form" method="post">
    <div class="layui-inline">
        <label class="layui-form-label">关键字</label>
        <div class="layui-input-inline" style="width: 300px">
            <input type="text" id="keyword" name="keyword" placeholder="请输入学生姓名(全名或关键字)" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-inline">
        <div class="layui-input-inline">
            <button  class="layui-btn" lay-submit lay-filter="doSearch">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

    <!-- 表格 -->
    <table class="layui-hide" id="teacherStu" lay-filter="StuInfo"></table>

    <!-- 头部工具栏 -->
    <script type="text/html" id="TeacherToolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i>添加新学生</button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="deleteAll" ><i class="layui-icon layui-icon-delete"></i>批量删除</button>
            <!--<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
        </div>
    </script>


    <!-- 行工具栏 -->
    <script type="text/html" id="TeacherBar">
        <a class="layui-btn layui-btn-xs" lay-event="update"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </script>

<!-- 弹出修改界面 -->
    <form class="layui-form" id="TeacherStuDetail" style="display: none" lay-filter="TeacherStuDetail">
        <div class="layui-form-item">
            <label class="layui-form-label">学号</label>
            <div class="layui-input-inline">
                <input type="text" name="id" lay-verify="required" lay-reqText="请输入正确的学号" placeholder="请输入学号" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="studentName" lay-verify="title" autocomplete="off" placeholder="请输入姓名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">班级</label>
            <div class="layui-input-inline">
                <input type="text" name="classesId" lay-verify="required" lay-reqText="请输入正确的班级" placeholder="请输入班级" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="1" title="男" checked="">
                <input type="radio" name="gender" value="2" title="女">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">出生地</label>
            <div class="layui-input-inline">
                <select name="bornProvice">
                    <option value="">请选择省</option>
                    <option value="11">北京市</option>
                    <option value="12">天津市</option>
                    <option value="13">河北省</option>
                    <option value="14">山西省</option>
                    <option value="43">湖南省</option>
                    <option value="44">广东省</option>
                    <option value="81">香港特别行政区</option>
                    <option value="82">澳门特别行政区</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="bornCity">
                    <option value="">请选择市</option>
                    <option value="1">广州市</option>
                    <option value="2">韶关市</option>
                    <option value="3">深圳市</option>
                    <option value="4">珠海市</option>
                    <option value="5">汕头市</option>
                    <option value="6">佛山市</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="bornDistrict">
                    <option value="">请选择县/区</option>
                    <option value="3">罗湖区</option>
                    <option value="4">福田区</option>
                    <option value="5">南山区</option>
                    <option value="6">宝安区</option>
                    <option value="7">龙岗区</option>
                    <option value="8">盐田区</option>
                    <option value="9">龙华区</option>
                </select>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出生地</label>
            <div class="layui-input-inline">
                <select name="bornStreet">
                    <option value="">请选择街道</option>
                    <option value="1000">南园街道</option>
                    <option value="2000">园岭街道</option>
                    <option value="4000">福田街道</option>
                    <option value="5000">沙头街道</option>
                    <option value="6000">香蜜湖街道</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="bornVillage">
                    <option value="">请选择小区</option>
                    <option value="1">皇御苑</option>
                    <option value="2">华强花园</option>
                    <option value="3">彩田村</option>
                    <option value="4">东海花园</option>
                    <option value="5">百花一路</option>
                    <option value="6">百花二路</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">籍贯</label>
            <div class="layui-input-inline">
                <select name="nativeProvice">
                    <option value="">请选择省</option>
                    <option value="11">北京市</option>
                    <option value="12">天津市</option>
                    <option value="13">河北省</option>
                    <option value="14">山西省</option>
                    <option value="43">湖南省</option>
                    <option value="44">广东省</option>
                    <option value="81">香港特别行政区</option>
                    <option value="82">澳门特别行政区</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="nativeCity">
                    <option value="">请选择市</option>
                    <option value="1">广州市</option>
                    <option value="2">韶关市</option>
                    <option value="3">深圳市</option>
                    <option value="4">珠海市</option>
                    <option value="5">汕头市</option>
                    <option value="6">佛山市</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="nativeDistrict">
                    <option value="">请选择县/区</option>
                    <option value="3">罗湖区</option>
                    <option value="4">福田区</option>
                    <option value="5">南山区</option>
                    <option value="6">宝安区</option>
                    <option value="7">龙岗区</option>
                    <option value="8">盐田区</option>
                    <option value="9">龙华区</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">籍贯</label>
            <div class="layui-input-inline">
                <select name="nativeStreet">
                    <option value="">请选择街道</option>
                    <option value="1000">南园街道</option>
                    <option value="2000">园岭街道</option>
                    <option value="4000">福田街道</option>
                    <option value="5000">沙头街道</option>
                    <option value="6000">香蜜湖街道</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="nativeVillage">
                    <option value="">请选择小区</option>
                    <option value="1">皇御苑</option>
                    <option value="2">华强花园</option>
                    <option value="3">彩田村</option>
                    <option value="4">东海花园</option>
                    <option value="5">百花一路</option>
                    <option value="6">百花二路</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">民族</label>
            <div class="layui-input-inline">
                <input type="text" name="nation" lay-verify="required" lay-reqText="请输入正确的民族" placeholder="请输入民族" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">国家</label>
            <div class="layui-input-inline">
                <input type="text" name="country" lay-verify="required" lay-reqText="请输入正确的国家" placeholder="请输入国籍" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">政治面貌</label>
            <div class="layui-input-inline">
                <input type="text" name="political" lay-verify="required" lay-reqText="请输入正确的政治面貌" placeholder="请输入政治面貌" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">证件类型</label>
            <div class="layui-input-inline">
                <select name="certificateId">
                    <option value="">请选择证件类型</option>
                    <option value="1">二代身份证</option>
                    <option value="2">出生证</option>
                    <option value="3">护照</option>
                    <option value="4">士官证</option>
                    <option value="5">港澳通行证</option>
                </select>
            </div>
            <label class="layui-form-label">证件号码</label>
            <div class="layui-input-inline">
                <input type="text" name="certificateNum" lay-verify="required" lay-reqText="请输入正确的证件号码" placeholder="请输入证件号码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">证件有效期</label>
            <div class="layui-input-inline">
                <input type="date" name="certificateTime" lay-verify="required" lay-reqText="请输入正确的有效期" placeholder="请选择证件有效期" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
                <input type="texts" name="age" lay-verify="required" lay-reqText="请输入正确的年龄" placeholder="请输入年龄" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">居住地址</label>
            <div class="layui-input-inline">
                <select name="provice">
                    <option value="">请选择省</option>
                    <option value="11">北京市</option>
                    <option value="12">天津市</option>
                    <option value="13">河北省</option>
                    <option value="14">山西省</option>
                    <option value="43">湖南省</option>
                    <option value="44">广东省</option>
                    <option value="81">香港特别行政区</option>
                    <option value="82">澳门特别行政区</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="city">
                    <option value="">请选择市</option>
                    <option value="1">广州市</option>
                    <option value="2">韶关市</option>
                    <option value="3">深圳市</option>
                    <option value="4">珠海市</option>
                    <option value="5">汕头市</option>
                    <option value="6">佛山市</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="district">
                    <option value="">请选择县/区</option>
                    <option value="3">罗湖区</option>
                    <option value="4">福田区</option>
                    <option value="5">南山区</option>
                    <option value="6">宝安区</option>
                    <option value="7">龙岗区</option>
                    <option value="8">盐田区</option>
                    <option value="9">龙华区</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">居住地址</label>
            <div class="layui-input-inline">
                <select name="street">
                    <option value="">请选择街道</option>
                    <option value="1000">南园街道</option>
                    <option value="2000">园岭街道</option>
                    <option value="4000">福田街道</option>
                    <option value="5000">沙头街道</option>
                    <option value="6000">香蜜湖街道</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="village">
                    <option value="">请选择小区</option>
                    <option value="1">皇御苑</option>
                    <option value="2">华强花园</option>
                    <option value="3">彩田村</option>
                    <option value="4">东海花园</option>
                    <option value="5">百花一路</option>
                    <option value="6">百花二路</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">血型</label>
            <div class="layui-input-inline">
                <input type="text" name="bloodtype" lay-verify="required" lay-reqText="请输入正确的血型" placeholder="请输入血型" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">父亲姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="fatherName" lay-verify="required" lay-reqText="请输入正确的父亲姓名" placeholder="请输入父亲姓名" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">母亲姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="motherName" lay-verify="required" lay-reqText="请输入正确的母亲姓名" placeholder="请输入母亲姓名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" lay-verify="required | phone" lay-reqText="请输入正确的联系电话" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">紧急电话</label>
            <div class="layui-input-inline">
                <input type="text" name="emergentPhone" lay-verify="required | phone" lay-reqText="请输入正确的紧急电话" placeholder="请输入紧急电话" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">宿舍</label>
            <div class="layui-input-inline">
                <select name="dormitoryId">
                    <option value="">请选择宿舍</option>
                    <option value="1">101</option>
                    <option value="2">201</option>
                    <option value="3">301</option>
                    <option value="4">101</option>
                    <option value="5">101</option>
                    <option value="6">201</option>
                    <option value="7">201</option>
                    <option value="8">301</option>
                    <option value="9">301</option>
                    <option value="10">301</option>
                    <option value="11">301</option>
                    <option value="12">301</option>
                </select>
            </div>
            <label class="layui-form-label">班主任</label>
            <div class="layui-input-inline">
                <select name="teacherId">
                    <option value="">请选择班主任</option>
                    <option value="1">文章</option>
                    <option value="3">数学王者</option>
                    <option value="4">物理大神</option>
                    <option value="5">化学牛人</option>
                    <option value="7">生物教授</option>
                    <option value="9">历史时钟</option>
                    <option value="10">政治角斗士</option>
                    <option value="13">地理游客</option>
                    <option value="15">体育达人</option>
                    <option value="16">英语健将</option>
                    <option value="17">杂家</option>
                    <option value="19">全才</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">身份</label>
            <div class="layui-input-inline">
                <select name="roleId">
                    <option value="">请选择身份</option>
                    <option value="1">学生</option>
                    <option value="2">班长</option>
                </select>
            </div>
            <label class="layui-form-label">理想大学</label>
            <div class="layui-input-inline">
                <input type="text" name="dreamSchool" lay-verify="required | phone" lay-reqText="请输入正确的理想大学" placeholder="请输入理想大学" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">独生子女</label>
            <div class="layui-input-inline">
                <input type="radio" name="isOnly" value="1" title="是">
                <input type="radio" name="isOnly" value="2" title="否" checked="">
            </div>
            <label class="layui-form-label">受过学前教育</label>
            <div class="layui-input-inline">
                <input type="radio" name="isPre" value="1" title="是">
                <input type="radio" name="isPre" value="2" title="否" checked="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">留守儿童</label>
            <div class="layui-input-inline">
                <input type="radio" name="isLeftOver" value="1" title="是">
                <input type="radio" name="isLeftOver" value="2" title="否" checked="">
            </div>
            <label class="layui-form-label">随迁子女</label>
            <div class="layui-input-inline">
                <input type="radio" name="isMigrant" value="1" title="是">
                <input type="radio" name="isMigrant" value="2" title="否" checked="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">进城务工随迁</label>
            <div class="layui-input-inline">
                <input type="radio" name="isMigrantWorker" value="1" title="是">
                <input type="radio" name="isMigrantWorker" value="2" title="否" checked="">
            </div>
            <label class="layui-form-label">孤儿</label>
            <div class="layui-input-inline">
                <input type="radio" name="isOrphan" value="1" title="是">
                <input type="radio" name="isOrphan" value="2" title="否" checked="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单亲</label>
            <div class="layui-input-inline">
                <input type="radio" name="isSingleParent" value="1" title="是">
                <input type="radio" name="isSingleParent" value="2" title="否" checked="">
            </div>
            <label class="layui-form-label">烈士或优抚子女</label>
            <div class="layui-input-inline">
                <input type="radio" name="isMartyr" value="1" title="是">
                <input type="radio" name="isMartyr" value="2" title="否" checked="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">残疾人</label>
            <div class="layui-input-inline">
                <input type="radio" name="isDisabled" value="1" title="是">
                <input type="radio" name="isDisabled" value="2" title="否" checked="">
            </div>
            <label class="layui-form-label">政府购买学位</label>
            <div class="layui-input-inline">
                <input type="radio" name="isAssinDegree" value="1" title="是">
                <input type="radio" name="isAssinDegree" value="2" title="否" checked="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">申请资助</label>
            <div class="layui-input-inline">
                <input type="radio" name="isSupport" value="1" title="是">
                <input type="radio" name="isSupport" value="2" title="否" checked="">
            </div>
            <label class="layui-form-label">享受一补</label>
            <div class="layui-input-inline">
                <input type="radio" name="isSubsidy" value="1" title="是">
                <input type="radio" name="isSubsidy" value="2" title="否" checked="">
            </div>
        </div>

    </form>

</body>
<script src="/layui.js" charset="utf-8"></script>
<script>

    layui.use(['table','layer','form'],function(){
        let table = layui.table;
        let layer=layui.layer;
        let form=layui.form;

        let tableInfo=table.render({
            elem: '#teacherStu'
            ,url:'/teacher/queryAllStu'
            ,toolbar: "#TeacherToolbar"
            ,title: '学生信息表'
            ,totalRow: true
            ,cols: [
                [
                {type: 'checkbox', fixed: 'left', totalRowText: '合计行',align:'center'}
                ,{field:'id', title:'学号', width:80, fixed: 'left', unresize: true, sort: true,align:'center'}
                ,{field:'studentName' ,width:80, title: '姓名',align:'center'}
                ,{field:'classes',width:120, title: '班级',align:'center', sort: true, templet:function (res) {
                    if(res.classes != null) return res.classes.classesName;
                    return "暂无";
                    }}
                ,{field:'genderName',width:80, title: '性别',align:'center'}
                ,{field:'bornplace', width:120,title: '出生地',align:'center'}
                ,{field:'nativePlace', width:120,title: '籍贯', sort: true,align:'center'}
                ,{field:'nation', width:80,title: '民族', sort: true,align:'center'}
                ,{field:'country',width:80,  title: '国籍',align:'center'}
                ,{field:'political',width:110,  title: '政治面貌', sort: true,align:'center'}
                ,{field:'certificate', width:110, title: '证件类型',align:'center', sort: true ,templet:function (res) {
                        return res.certificate.certificateName;
                    }}
                ,{field:'cettificateNum',width:200,  title: '证件号码',align:'center'}
                ,{field:'certificateTime',width:120,  title: '证件有效期', sort: true,align:'center'}
                ,{field:'age', width:80,title: '年龄', sort: true,align:'center'}
                ,{field:'address', width:120,title: '居住地址', sort: true,align:'center'}
                ,{field:'bloodtype', width:80,title: '血型', sort: true,align:'center'}
                ,{field:'fatherName', width:120, title: '父亲姓名',align:'center'}
                ,{field:'motherName', width:120, title: '母亲姓名',align:'center'}
                ,{field:'phone',width:150,  title: '电话', sort: true,align:'center'}
                ,{field:'emergentPhone',width:150, title: '紧急联系电话', sort: true,align:'center'}
                ,{field:'dormitory', width:120, title: '宿舍',align:'center', sort: true,templet:function (res) {
                        return res.dormitory.dormitoryName;
                    }}
                ,{field:'teachers',width:120,  title: '班主任',align:'center',templet:function (res) {
                        return res.teachers.teachersName;
                    }}
                ,{field:'role',width:80, title: '身份',align:'center', sort: true,templet:function (res) {
                        return res.role.name;
                    }}
                ,{field:'isPreName', width:120, title: '独生子女', sort: true,align:'center'}
                ,{field:'isOnlyName',width:150,  title: '受过学前教育', sort: true,align:'center'}
                ,{field:'isLeftOverName', width:120, title: '留守儿童', sort: true,align:'center'}
                ,{field:'isMigrantName', width:120, title: '随迁子女', sort: true,align:'center'}
                ,{field:'isMigrantWorkerName',width:150,  title: '进城务工随迁', sort: true,align:'center'}
                ,{field:'isOrphanName',width:80,  title: '孤儿', sort: true,align:'center'}
                ,{field:'isSingleParentName', width:80,title: '单亲', sort: true,align:'center'}
                ,{field:'isMartyrName',width:150,  title: '烈士或优抚子女', sort: true,align:'center'}
                ,{field:'isDisabledName',width:80,  title: '残疾人', sort: true,align:'center'}
                ,{field:'isAssinDegreeName', width:150, title: '政府购买学位', sort: true,align:'center'}
                ,{field:'isSupportName', width:150, title: '需要申请资助', sort: true,align:'center'}
                ,{field:'isSubsidyName', width:120, title: '享受一补', sort: true,align:'center'}
                ,{title:"操作",toolbar:"#TeacherBar" ,width:150,fixed:'right',align:'center'}
            ]],
            page: true
            ,response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.items //解析数据列表
                };
                // search();
            }
        });

        //监听头部工具栏事件
        table.on("toolbar(StuInfo)",function (obj) {
            switch (obj.event) {
                case 'add':
                    openAddStu();
                    break;
                case 'deleteAll':
                    openUpdateStu();
                    break;
            }
        });

        //监听行工具栏事件
        table.on('tool(StuInfo)',function (obj) {

            switch (obj.event) {
                case 'update':
                    openUpdateStu(obj.data);
                    break;
                case 'delete':
                    if (TeacherDeleteStu(obj.data)) {
                        obj.del();
                    }
                    break;
            }
        });

        function openAddStu() {
            layer.open({
                type:2,//弹出层类型
                title:"添加新生",
                area:['800px','600px'],
                content:'http://localhost:8080/teachers/TeacherAddStu.html',
                success:function () {
                    $("#addStu")[0].reset()
                }
            })
        }

        let url;//提交地址
        let mainIndex;//窗口索引
        function openUpdateStu(data) {
           mainIndex= layer.open({
                type:1,//弹出层类型
                title:"修改学生信息",
                area:['800px','600px'],
                shade: 0,
                btn: ['提交', '重置'],
                btn1: function(index, layero){
                   let data = form.val("TeacherStuDetail");
                   $.post("/teacher/modifyStu",data,function (res) {
                       if (res.success=="true"){
                           layer.alert("修改成功！",{icon:6,time:2000})
                       }
                   });
                   layer.closeAll();
                   return true;
                },btn2: function(index, layero){
                   $("#TeacherStuDetail")[0].reset();
                   // $("#TeacherStuDetail").reset();
                   return false;
               },
               cancel: function(layero,index){
                   layer.closeAll();
               },
                content:$("#TeacherStuDetail"),
                success:function () {
                    //表单数据回显
                    form.val("TeacherStuDetail",data);
                }
            })

        }
        function TeacherDeleteStu(data) {
           layer.confirm("确定删除吗？",{icon:3,title:"提示"},function (deleteStu) {
              $.post("/teacher/deleteStu",{id:data.id},function (res) { // "id="+data.id
                  if (res.success=="true"){
                      layer.alert("删除成功！",{icon:6,time: 2000});
                      // layer.close(deleteStu);
                  } else{
                      layer.alert(res.msg,{icon:5,time: 2000})
                  }
                  layer.close(deleteStu);
              })
           })

        }

        //监听搜索提交事件
        form.on("submit(doSearch)",function (data) {
            tableInfo.reload({
                where:data.field,
                page:{
                    curr:1
                }
            });
            return false;
        })

    });

</script>
</html>